package com.hsy.linemoney.modules.my.editinformation;

import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hsy.linemoney.R;
import com.hsy.linemoney.modules.common.CommonBaseActivityWithSimpleActionBar;

/**
 * Created by Administrator on 2016/7/12.
 */
public class EditPasswordActivity extends CommonBaseActivityWithSimpleActionBar {

    private EditText password_edit, new_password_edit, new_password_edit_again;
    private TextView password_edit_line, new_password_edit_line, new_password_edit_again_line;
    private Handler handler;

    @Override
    public boolean onActionBarRightButtonClicked(ImageButton rightButton) {
        finish();
        return super.onActionBarRightButtonClicked(rightButton);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setTitle(R.string.title_my_edit_password);
        setRightButtonVisiblity(View.VISIBLE);
        setRightButtonText(getString(R.string.my_edit_common_right_save));
        setRightButtonTextColor(R.color.common_white);

        setContentView(R.layout.activity_edit_password);

        password_edit_line = F(R.id.password_edit_line);
        password_edit = F(R.id.password_edit);
        editTextLine(password_edit, password_edit_line);

        new_password_edit_line = F(R.id.new_password_edit_line);
        new_password_edit = F(R.id.new_password_edit);
        editTextLine(new_password_edit, new_password_edit_line);

        new_password_edit_again_line = F(R.id.new_password_edit_again_line);
        new_password_edit_again = F(R.id.new_password_edit_again);
        editTextLine(new_password_edit_again, new_password_edit_again_line);

        handler = new Handler();

        password_edit.setFocusable(true);

        password_edit.setFocusableInTouchMode(true);

        password_edit.requestFocus();

        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                InputMethodManager inputManager =

                        (InputMethodManager) password_edit.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

                inputManager.showSoftInput(password_edit, 0);
            }
        }, 100);

    }

    private void editTextLine(EditText editText, final TextView line) {
        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    line.setBackgroundDrawable(getResources().getDrawable(R.color.color_action_bar_bg));
                } else {
                    line.setBackgroundDrawable(getResources().getDrawable(R.color.line));
                }
            }
        });

    }
}
